home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Reference Guide
/
C-C++ Interactive Reference Guide.iso
/
c_ref
/
csource3
/
156_01
/
profile.doc
< prev
next >
Wrap
Text File
|
1985-08-21
|
3KB
|
73 lines
PROFILE
If the "profile and trace" option of the compiler is used, each
call to err() results in a walkback trace of function calls.
(Err() is in the IOLIB library. For details, see IOLIB.DOC.) In
addition, an execution profile is displayed on the console at
program termination (call to exit()). The profile consists of a
list of the functions and the number of times (up to 999999)
each was called. This is sometimes useful for debugging (to
spot functions that are never called), but is most valuable for
program execution time optimization. If you're trying to speed
up a program, pay close attention to the functions that are
called a lot of times!
The "profile and trace" option of the compiler causes it to add
a call to the profile printout function just before exiting to
the operating system. The code at the beginning of the program
then looks like this:
; ORG 100H ;implied - ZLINK default
LD HL,(6)
LD SP,HL ;initialize stack
CALL CCGO ;initialize other things
CALL QMAIN ;execute the user's program
LD HL,CC2 ;pointer to 1st function
CALL CCCALLS ;print the profile
CALL QEXIT ;exit to operating system
A header and two calls are also added to the code generated
for each function. The function header contains a pointer, a
counter, and a string with the function name.
;trials()
CC2: DW CC3 ;function pointer. Points to the
;function pointer in the textually
;following function, or contains a
;zero if this is the last one.
DB 0,0,0 ;a three byte BCD counter for the
;number of times this function has been
;called. (permits 999999 calls before
;overflow.)
CC4: DB 'trials',0 ;the function name
QTRIALS:
LD HL,CC4 ;save pointer to function
PUSH HL ; header block.
CALL CCREGIS ;register function entry.
;ccregis() pushes onto the stack a
;pointer to the function that called
;this one, and saves in CURRENT a
;pointer to this one.
;{ z=a(x);
LD HL,QX
... ;regular code.
;}
CALL CCLEAVI ;register function return
;(resets CURRENT to point to
;the function that called this
;one)
POP BC ;discard the pointer added by
;ccregis().
POP BC ;discard the pointer to the
;header block of this function.
RET
Note that this method permits a walkback trace even in the
presence of recursive function calls.